package com.minibobbo.utilities.spe;

public class SpeValueModule {
	String name;
	int value;
	int maxValue;

	/**
	 * Generic constructor.
	 */
	public SpeValueModule() {

	}

	/**
	 * 
	 * @param name
	 *            Name of the value
	 * @param value
	 *            The amount this value should be set to.
	 * @param maxValue
	 *            The maximum amount this value can get to.
	 */
	public SpeValueModule(String name, int value, int maxValue) {
		this.name = name;
		this.value = value;
		this.maxValue = maxValue;
	}

	/**
	 * Constructor that sets the current value to the max value when created.
	 * 
	 * @param name
	 *            Name of the value
	 * @param maxValue
	 *            The maximum amount of the value
	 */
	public SpeValueModule(String name, int maxValue) {
		this.name = name;
		this.maxValue = maxValue;
		value = maxValue;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setValue(int value) {
		this.value = value;
	}

	public void setMaxValue(int maxValue) {
		this.maxValue = value;
	}

	public int getValue() {
		return value;
	}

	/**
	 * Do we have enough in this value?
	 * 
	 * @param check
	 *            the number to check
	 * @return True if we have enough. Otherwise false.
	 */
	public boolean haveEnough(int check) {
		if (value >= check)
			return true;
		else
			return false;
	}

	/**
	 * Increases the number of this value
	 * 
	 * @param numberToAdd
	 *            The amount this value should be increased up to the maximum.
	 * @return True if we are at max.
	 */
	public boolean add(int numberToAdd) {
		value += numberToAdd;
		if (value >= maxValue) {
			value = maxValue;
			return true;
		} else
			return false;
	}

	/**
	 * Subtracts the amount from this value
	 * 
	 * @param numberToSubtract
	 *            The amount this value should be decreased down to 0.
	 * @return True if we are at 0. Otherwise false;
	 */
	public boolean subtract(int numberToSubtract) {
		value -= numberToSubtract;
		if (value <= 0) {
			value = 0;
			return true;
		} else
			return false;

	}
	
	/**
	 * Sets this value to the maximum amount.
	 */
	public void max() {
		value = maxValue;
	}

}
